/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tecbooks;

/**
 *
 * @author Alan Lemos
 */
public class BuscaLivros extends javax.swing.JFrame {

    /**
     * Creates new form BuscaLivros
     */
    public BuscaLivros() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblIdBuscaLivros = new javax.swing.JLabel();
        txtIdBuscaLivros = new javax.swing.JTextField();
        btnBuscaLivros = new javax.swing.JButton();
        btnBuscaLivrosSair = new javax.swing.JButton();
        paneInfo = new javax.swing.JPanel();
        lblBuscaLivros = new javax.swing.JLabel();
        lblBuscaLivrosNome1 = new javax.swing.JLabel();
        lblBuscaLivrosNome2 = new javax.swing.JLabel();
        lblBuscaLivrosNome3 = new javax.swing.JLabel();
        lblBuscaLivrosAviso = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Buscar Livro");
        setMinimumSize(new java.awt.Dimension(400, 300));

        lblIdBuscaLivros.setText("Id:");

        txtIdBuscaLivros.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtIdBuscaLivrosapenasNumeros(evt);
            }
        });

        btnBuscaLivros.setText("Buscar");
        btnBuscaLivros.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscaLivrosActionPerformed(evt);
            }
        });

        btnBuscaLivrosSair.setText("Sair");
        btnBuscaLivrosSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscaLivrosSairActionPerformed(evt);
            }
        });

        paneInfo.setVisible(false);
        paneInfo.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, new java.awt.Color(0, 0, 0), new java.awt.Color(255, 255, 0), new java.awt.Color(255, 255, 0), new java.awt.Color(0, 0, 0)), "Dados do LIvro"));

        lblBuscaLivros.setText("Gênero: ");

        lblBuscaLivrosNome1.setText("Autor(s):");

        lblBuscaLivrosNome2.setText("Editora:");

        lblBuscaLivrosNome3.setText("Id:");

        javax.swing.GroupLayout paneInfoLayout = new javax.swing.GroupLayout(paneInfo);
        paneInfo.setLayout(paneInfoLayout);
        paneInfoLayout.setHorizontalGroup(
            paneInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(paneInfoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(paneInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblBuscaLivros, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(paneInfoLayout.createSequentialGroup()
                        .addComponent(lblBuscaLivrosNome3, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 242, Short.MAX_VALUE))
                    .addComponent(lblBuscaLivrosNome1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblBuscaLivrosNome2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        paneInfoLayout.setVerticalGroup(
            paneInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(paneInfoLayout.createSequentialGroup()
                .addGap(17, 17, 17)
                .addComponent(lblBuscaLivrosNome3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblBuscaLivros)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblBuscaLivrosNome1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblBuscaLivrosNome2)
                .addContainerGap(26, Short.MAX_VALUE))
        );

        lblBuscaLivrosAviso.setForeground(new java.awt.Color(255, 0, 0));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addComponent(paneInfo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(lblIdBuscaLivros)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblBuscaLivrosAviso, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(txtIdBuscaLivros, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnBuscaLivros)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnBuscaLivrosSair)))))
                .addContainerGap(34, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblIdBuscaLivros)
                    .addComponent(txtIdBuscaLivros, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnBuscaLivros)
                    .addComponent(btnBuscaLivrosSair))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblBuscaLivrosAviso, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(7, 7, 7)
                .addComponent(paneInfo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(53, Short.MAX_VALUE))
        );

        paneInfo.getAccessibleContext().setAccessibleName("Dados do Livro");
        paneInfo.getAccessibleContext().setAccessibleDescription("Dados do Livro");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtIdBuscaLivrosapenasNumeros(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtIdBuscaLivrosapenasNumeros
        // TODO add your handling code here:
        String numeros = "0123456789";
        if((int)evt.getKeyChar() == 10 && txtIdBuscaLivros.getText().endsWith("1234")){
            paneInfo.setVisible(true);
        }
        else{
            if((int)evt.getKeyChar() == 10 && txtIdBuscaLivros.getText().endsWith("")){
               lblBuscaLivrosAviso.setText("Campo Vazio!");
               paneInfo.setVisible(false);
            }
            else{
                if(!numeros.contains(evt.getKeyChar()+"") && (int)evt.getKeyChar() != 8){
                    evt.consume();
                    lblBuscaLivrosAviso.setText("Por favor, informe apenas números!");
                }
                else{
                    paneInfo.setVisible(false);
                    lblBuscaLivrosAviso.setText("");
                }
            }
      }
    }//GEN-LAST:event_txtIdBuscaLivrosapenasNumeros

    private void btnBuscaLivrosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscaLivrosActionPerformed
        // TODO add your handling code here:
        //trata txtId
        if ( txtIdBuscaLivros.getText().equals("1234")){
            paneInfo.setVisible(true);
        }
        else{
            if(txtIdBuscaLivros.getText().equals("")){
                lblBuscaLivrosAviso.setText("Campo Vazio!");
            }
            else{
            lblBuscaLivrosAviso.setText("Livro não cadastrado!");
            paneInfo.setVisible(false);
            }
        }
    }//GEN-LAST:event_btnBuscaLivrosActionPerformed

    private void btnBuscaLivrosSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscaLivrosSairActionPerformed
        // TODO add your handling code here:
        dispose();
        new TelaPrincipal().setVisible(true);
    }//GEN-LAST:event_btnBuscaLivrosSairActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(BuscaLivros.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(BuscaLivros.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(BuscaLivros.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(BuscaLivros.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new BuscaLivros().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBuscaLivros;
    private javax.swing.JButton btnBuscaLivrosSair;
    private javax.swing.JLabel lblBuscaLivros;
    private javax.swing.JLabel lblBuscaLivrosAviso;
    private javax.swing.JLabel lblBuscaLivrosNome1;
    private javax.swing.JLabel lblBuscaLivrosNome2;
    private javax.swing.JLabel lblBuscaLivrosNome3;
    private javax.swing.JLabel lblIdBuscaLivros;
    private javax.swing.JPanel paneInfo;
    private javax.swing.JTextField txtIdBuscaLivros;
    // End of variables declaration//GEN-END:variables
}
